<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/static/component/pear/css/pear.css"/>
    <script src="/static/component/layui/layui.js"></script>
    <script src="/static/component/pear/pear.js"></script>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <table id="dataTable" lay-filter="dataTable"></table>
    </div>
</div>
<script type="text/html" id="options">
    <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i>
    </button>
</script>
<script>
    layui.use(['table', 'form', 'jquery', 'common', 'laydate', 'dropdown'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let common = layui.common;
        let laydate = layui.laydate;
        let dropdown = layui.dropdown;
        let MODULE_PATH = "{$Request.root}/study.student_action/";

        laydate.render({
            elem: '#add_time'
        });

        //初演示
        dropdown.render({
            elem: '.demo1'
            , data: [{
                title: '活动情况'
                , id: 1
            }, {
                title: '更换尿布'
                , id: 2
            }, {
                title: '喂奶情况'
                , id: 3
            }, {
                title: '用餐情况'
                , id: 4
            }, {
                title: '用药情况'
                , id: 5
            }, {
                title: '睡觉情况'
                , id: 6
            }, {
                title: '清洁情况'
                , id: 7
            }, {
                title: '饮品情况'
                , id: 8
            }, {
                title: '便便情况'
                , id: 9
            }, {
                title: '情绪情况'
                , id: 10
            }, {
                title: '到校情况'
                , id: 11
            }, {
                title: '离校情况'
                , id: 12
            }, {
                title: '体温'
                , id: 13
            }, {
                title: '突发事件'
                , id: 14
            }, {
                title: '行为观察'
                , id: 15
            }, {
                title: '添置'
                , id: 16
            }, {
                title: '备注'
                , id: 17
            }, {
                title: '缺勤'
                , id: 18
            }, {
                title: '视频'
                , id: 19
            }, {
                title: '健康'
                , id: 20
            }, {
                title: '发展学习'
                , id: 21
            }, {
                title: '更换衣物'
                , id: 22
            }, {
                title: '如厕记录'
                , id: 23
            }, {
                title: '今日日记'
                , id: 24
            }
            ]
            , click: function (obj) {
                let class_id = $('#class_id').val();
                let student_id = $('#student_id').val();
                if (!class_id) {
                    layer.msg('请选择班级')
                    return
                }
                switch (obj.id) {
                    case 1:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '学生活动',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.action_situation/" + 'add?class_id='+class_id+'&student_id='+student_id
                        });
                        break;
                    case 2:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '更换尿布',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.replace_diaper/" + 'add?class_id='+class_id+'&student_id='+student_id
                        });
                        break;
                    case 3:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '喂奶情况',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.action_nurse/" + 'add?class_id='+class_id+'&student_id='+student_id
                        });
                        break;
                    case 4:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '用餐情况',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.action_eat/" + 'add?class_id='+class_id+'&student_id='+student_id
                        });
                        break;
                    case 5:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '用药情况',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.action_medication/" + 'add?class_id='+class_id+'&student_id='+student_id
                        });
                        break;
                    case 6:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '睡觉情况',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.action_sleep/" + 'add?class_id='+class_id+'&student_id='+student_id
                        });
                        break;
                    case 7:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '清洁情况',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.action_clean/" + 'add?class_id='+class_id+'&student_id='+student_id
                        });
                        break;
                    case 8:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '饮品情况',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.action_drink/" + 'add?class_id='+class_id+'&student_id='+student_id
                        });
                        break;
                    case 9:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '便便情况',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.action_poop/" + 'add?class_id='+class_id+'&student_id='+student_id
                        });
                        break;
                    case 10:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '情绪情况',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.action_emotion/" + 'add?class_id='+class_id+'&student_id='+student_id
                        });
                        break;
                    case 11:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '到校情况',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.action_attendance/" + 'add?class_id='+class_id+'&attendance_type=到校&student_id='+student_id
                        });
                        break;
                    case 12:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '离校情况',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.action_attendance/" + 'add?class_id='+class_id+'&attendance_type=离校&student_id='+student_id
                        });
                        break;
                    case 13:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '体温',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.action_temperature/" + 'add?class_id='+class_id+'&student_id='+student_id
                        });

                        break;
                    case 14:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '突发事件',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.action_burst/" + 'add?class_id='+class_id+'&student_id='+student_id
                        });
                        break;
                    case 15:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '行为观察',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.action_behavior/" + 'add?class_id='+class_id+'&student_id='+student_id
                        });
                        break;
                    case 16:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '添置',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.action_acquire/" + 'add?class_id='+class_id+'&student_id='+student_id
                        });

                        break;
                    case 17:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '备注',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.action_remarks/" + 'add?class_id='+class_id+'&student_id='+student_id
                        });
                        break;
                    case 18:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '缺勤',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.action_absence/" + 'add?class_id='+class_id+'&student_id='+student_id
                        });
                        break;
                    case 19:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '视频',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.action_shot/" + 'add?class_id='+class_id+'&student_id='+student_id
                        });
                        break;
                    case 20:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '健康',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.action_healthy/" + 'add?class_id='+class_id+'&student_id='+student_id
                        });
                        break;
                    case 21:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '发展学习',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.action_study/" + 'add?class_id='+class_id+'&student_id='+student_id
                        });
                        break;
                    case 22:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '更换衣物',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.action_clothes/" + 'add?class_id='+class_id+'&student_id='+student_id
                        });
                        action_name = ''
                        break;
                    case 23:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '如厕记录',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.action_toilet/" + 'add?class_id='+class_id+'&student_id='+student_id
                        });
                        break;
                    case 24:
                        layer.open({
                            type: 2,
                            maxmin: true,
                            title: '今日日记',
                            shade: 0.1,
                            area: screen(),
                            content: "{$Request.root}/student.action_dairy/" + 'add?class_id='+class_id+'&student_id='+student_id
                        });
                        break;
                    default:
                        action_name = ''
                        break;
                }
            }

        });

        let cols = [
            [{
                type: 'checkbox'
            }, {
                field: "id",
                title: "",
                unresize: "true",
                align: "center"
            }, {
                field: "student_id",
                title: "学生",
                unresize: "true",
                align: "center", templet: d => {
                    return d.get_student ? d.get_student.username : ''
                }
            }, {
                title: "上传人",
                unresize: "true",
                align: "center", templet: d => {
                    return d.get_teacher ? d.get_teacher.username : ''
                }
            }, {
                field: "action_type",
                title: "活动类型	",
                unresize: "true",
                align: "center", templet: d => {
                    let action_name = ''
                    switch (d.action_type) {
                        case 1:
                            action_name = '活动情况'
                            break;
                        case 2:
                            action_name = '更换尿布'
                            break;
                        case 3:
                            action_name = '喂奶情况'
                            break;
                        case 4:
                            action_name = '用餐情况'
                            break;
                        case 5:
                            action_name = '用药情况'
                            break;
                        case 6:
                            action_name = '睡觉情况'
                            break;
                        case 7:
                            action_name = '清洁情况'
                            break;
                        case 8:
                            action_name = '饮品情况'
                            break;
                        case 9:
                            action_name = '便便情况'
                            break;
                        case 10:
                            action_name = '情绪情况'
                            break;
                        case 11:
                            action_name = '到校情况'
                            break;
                        case 12:
                            action_name = '离校情况'
                            break;
                        case 13:
                            action_name = '体温'
                            break;
                        case 14:
                            action_name = '突发事件'
                            break;
                        case 15:
                            action_name = '行为观察'
                            break;
                        case 16:
                            action_name = '添置'
                            break;
                        case 17:
                            action_name = '备注'
                            break;
                        case 18:
                            action_name = '缺勤'
                            break;
                        case 19:
                            action_name = '视频'
                            break;
                        case 20:
                            action_name = '健康'
                            break;
                        case 21:
                            action_name = '发展学习'
                            break;
                        case 22:
                            action_name = '更换衣物'
                            break;
                        case 23:
                            action_name = '如厕记录'
                            break;
                        case 24:
                            action_name = '今日日记'
                            break;
                        default:
                            action_name = ''
                            break;
                    }
                    return action_name
                }
            }, {
                field: "action_id",
                title: "活动详情",
                unresize: "true",
                align: "center",
                templet: d => {
                    let action_name = ''
                    switch (d.action_type) {
                        case 1:
                            action_name = `
<div>名称:${d.action.situation_name}|详情: ${d.action.situation_detail}|图片:`
                            if (d.action.situation_img.length > 0) {
                                $.each(d.action.situation_img, function (k, v) {
                                    action_name += `<img src="${v}" style="height: 50px;">`
                                })
                            }
                            action_name += '</div>'
                            break;
                        case 2:
                            action_name = `是否更换尿布: ${d.action.replace_diaper}|屁股情况: ${d.action.diaper_type}|说明: ${d.action.replace_info}`
                            break;
                        case 3:
                            action_name = `时间: ${d.add_time}|喂奶种类:${d.action.nurse_type}|数量:${d.action.diaper_num}毫升|说明: ${d.action.action_info}`
                            break;
                        case 4:
                            action_name = `${d.action.eat_type} | 饭量: ${d.action.eat_num}| 食物: ${d.action.eat_food}| 说明: ${d.action.action_info}`
                            break;
                        case 5:
                            action_name = `说明: ${d.action.action_info} | 图片: <img src="${d.action.sign_img}" style="height: 50px;">`
                            break;
                        case 6:
                            action_name = `开始时间: ${d.action.start_time} | 结束时间: ${d.action.end_time} | 睡眠时间: ${d.action.sleep_time}| 睡眠情况: ${d.action.sleep_type}| 说明: ${d.action.action_info}`
                            break;
                        case 7:
                            action_name = `清洁类型: ${d.action.clean_type} | 清洁情况: ${d.action.clean_info} | 是否自理: ${d.action.is_self}| 说明: ${d.action.action_info}`
                            break;
                        case 8:
                            action_name = `单位: ${d.action.drink_tool} | 饮品: ${d.action.drink_type} | 说明: ${d.action.action_info}`
                            break;
                        case 9:
                            action_name = `说明: ${d.action.action_info} | 图片: `
                            if (d.action.poop_detail.length > 0) {
                                $.each(d.action.poop_detail, function (k, v) {
                                    action_name += `<img src="${v}" style="height: 50px;">`
                                })
                            }
                            break;
                        case 10:
                            action_name = `情绪类型: ${d.action.emotion_detail} | 说明: ${d.action.action_info}`
                            break;
                        case 11:
                            action_name = `送达人: ${d.action.shuttle_type} | 说明: ${d.action.action_info} | 图片: <img src="${d.action.shuttle_img}" style="height: 50px;">`
                            break;
                        case 12:
                            action_name = `接娃人: ${d.action.shuttle_type} | 说明: ${d.action.action_info} | 图片: <img src="${d.action.shuttle_img}" style="height: 50px;">`
                            break;
                        case 13:
                            action_name = `体温: ${d.action.temperature} | 说明: ${d.action.action_info}`
                            break;
                        case 14:
                            action_name = `事件: ${d.action.burst_info} | 说明: ${d.action.action_info}`
                            if (d.action.burst_img.length > 0) {
                                $.each(d.action.burst_img, function (k, v) {
                                    action_name += `<img src="${v}" style="height: 50px;">`
                                })
                            }
                            break;
                        case 15:
                            action_name = `行为: ${d.action.behavior_info} | 说明: ${d.action.action_info}`
                            if (d.action.behavior_img.length > 0) {
                                $.each(d.action.behavior_img, function (k, v) {
                                    action_name += `<img src="${v}" style="height: 50px;">`
                                })
                            }
                            break;
                        case 16:
                            action_name = `添置物品: ${d.action.acquire_info} | 说明: ${d.action.action_info}`
                            break;
                        case 17:
                            action_name = `备注: ${d.action.action_info}`
                            break;
                        case 18:
                            action_name = `缺勤原因: ${d.action.absence_type} | 说明: ${d.action.action_info}|开始时间: ${d.action.start_time} | 结束时间: ${d.action.end_time}`
                            break;
                        case 19:
                            action_name = ` 说明: ${d.action.action_info} |`
                            if (d.action.shot_info.length > 0) {
                                $.each(d.action.shot_info, function (k, v) {
                                    action_name += `<img src="${v}" style="height: 50px;">`
                                })
                            }
                            break;
                        case 20:
                            action_name = `健康状态: ${d.action.healthy_type} | 说明: ${d.action.action_info} | 情况:`
                            if (d.action.healthy_info.length > 0) {
                                $.each(d.action.healthy_info, function (k, v) {
                                    action_name += v + ','
                                })
                            }
                            break;
                        case 21:
                            action_name = ` 说明: ${d.action.action_info} |`
                            if (d.action.study_img.length > 0) {
                                $.each(d.action.study_img, function (k, v) {
                                    action_name += `<img src="${v}" style="height: 50px;">`
                                })
                            }
                            break;
                        case 22:
                            action_name = `衣物: ${d.action.clothes_type} | 说明: ${d.action.action_info}`
                            break;
                        case 23:
                            action_name = `类型: ${d.action.toilet_type} | 说明: ${d.action.action_info}|图片:<img src="${d.action.toilet_img}" style="height: 50px;">`
                            break;
                        case 24:
                            action_name = `说明: ${d.action.action_info} |`
                            if (d.action.dairy_img.length > 0) {
                                $.each(d.action.dairy_img, function (k, v) {
                                    action_name += `<img src="${v}" style="height: 50px;">`
                                })
                            }
                            break;
                        default:
                            action_name = ''
                            break;
                    }
                    return action_name
                }
            }, {
                field: "add_time",
                title: "发布时间",
                unresize: "true",
                align: "center"
            }, {
                title: '操作',
                toolbar: '#options',
                unresize: true,
                align: 'center',
                width: 180,
            }
            ]
        ]

        table.render({
            elem: '#dataTable',
            url: MODULE_PATH + 'index?student_id={$id}',
            page: true,
            cols: cols,
            cellMinWidth: 100,
            skin: 'line',
            toolbar: '#toolbar',
            limit: 20,
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports']
        });

        table.on('tool(dataTable)', function (obj) {
            if (obj.event === 'remove') {
                window.remove(obj);
            } else if (obj.event === 'edit') {
                window.edit(obj);
            }
        });

        form.on('select(first_class)', function (data) {
            let class_id = data.value;
            if (!class_id) {
                $('#second_class').empty().html(`<option value="">请选择班级</option>`)
                form.render()
                return
            }
            let html = `<option value="">全部</option>`;
            $.get(MODULE_PATH+'getSecondClass', {class_id: class_id}, function (res) {
                $.each(res, function (k,v) {
                    html += `<option value="${v.id}">${v.username}</option>`
                });
                $('#student_id').empty().html(html)
                form.render()
            })
        })

        table.on('toolbar(dataTable)', function (obj) {
            if (obj.event === 'add') {
                window.add();
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'batchRemove') {
                window.batchRemove(obj);
            } else if (obj.event === 'recycle') {
                window.recycle(obj);
            }
        });

        form.on('submit(query)', function (data) {
            table.reload('dataTable', {
                where: data.field,
                page: {curr: 1}
            })

            return false;
        });

        //弹出窗设置 自己设置弹出百分比
        function screen() {
            if (typeof width !== 'number' || width === 0) {
                width = $(window).width() * 0.8;
            }
            if (typeof height !== 'number' || height === 0) {
                height = $(window).height() - 20;
            }
            return [width + 'px', height + 'px'];
        }

        window.add = function () {
            layer.open({
                type: 2,
                maxmin: true,
                title: '新增学生活动',
                shade: 0.1,
                area: screen(),
                content: MODULE_PATH + 'add'
            });
        }

        window.edit = function (obj) {
            layer.open({
                type: 2,
                maxmin: true,
                title: '修改学生活动',
                shade: 0.1,
                area: screen(),
                content: MODULE_PATH + 'edit/id/' + obj.data['id']
            });
        }

        window.recycle = function () {
            layer.open({
                type: 2,
                maxmin: true,
                title: '回收站',
                shade: 0.1,
                area: screen(),
                content: MODULE_PATH + 'recycle',
                cancel: function () {
                    table.reload('dataTable');
                }
            });
        }


        window.remove = function (obj) {
            layer.confirm('确定要删除该学生活动', {
                icon: 3,
                title: '提示'
            }, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + 'remove',
                    data: {id: obj.data['id']},
                    dataType: 'json',
                    type: 'POST',
                    success: function (res) {
                        layer.close(loading);
                        //判断有没有权限
                        if (res && res.code == 999) {
                            layer.msg(res.msg, {
                                icon: 5,
                                time: 2000,
                            })
                            return false;
                        } else if (res.code == 200) {
                            layer.msg(res.msg, {
                                icon: 1,
                                time: 1000
                            }, function () {
                                obj.del();
                            });
                        } else {
                            layer.msg(res.msg, {
                                icon: 2,
                                time: 1000
                            });
                        }
                    }
                })
            });
        }

        window.batchRemove = function (obj) {
            let data = table.checkStatus(obj.config.id).data;
            if (data.length === 0) {
                layer.msg("未选中数据", {
                    icon: 3,
                    time: 1000
                });
                return false;
            }
            var ids = []
            var hasCheck = table.checkStatus('dataTable')
            var hasCheckData = hasCheck.data
            if (hasCheckData.length > 0) {
                $.each(hasCheckData, function (index, element) {
                    ids.push(element.id)
                })
            }
            layer.confirm('确定要删除这些学生活动', {
                icon: 3,
                title: '提示'
            }, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + 'batchRemove',
                    data: {ids: ids},
                    dataType: 'json',
                    type: 'POST',
                    success: function (res) {
                        layer.close(loading);
                        //判断有没有权限
                        if (res && res.code == 999) {
                            layer.msg(res.msg, {
                                icon: 5,
                                time: 2000,
                            })
                            return false;
                        } else if (res.code == 200) {
                            layer.msg(res.msg, {
                                icon: 1,
                                time: 1000
                            }, function () {
                                table.reload('dataTable');
                            });
                        } else {
                            layer.msg(res.msg, {
                                icon: 2,
                                time: 1000
                            });
                        }
                    }
                })
            });
        }

        window.refresh = function (param) {
            table.reload('dataTable');
        }
    })
</script>
</body>
</html>
